<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="../session.jsp"%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp"%>
  	<script src="resources/js/jquery.js"></script>
	<script src="resources/js/bootstrap.min.js"></script>
  </head>
  <body>
  	<%@ include file="../menu.jsp"%>
	<div class="container">
		<div class="page-header">
			<h2>관리자 계정수정</h2>
		</div>

		<form id="editAdmin" class="form-horizontal" role="form" method="post">
			<fieldset>
			
				<input type="hidden" name="idAdmin" value="${item.idAdmin}" />
				<input type="hidden" name="page" value="${page}" />
			
				<div class="form-group">
					<label for="nickName" class="col-md-2 control-label">닉네임</label>
					<div class="col-md-10">
						<input type="text" class="form-control" name="nickName" value="${item.nickName}" placeholder="닉네임을 입력하세요" />
					</div>
				</div>

				<div class="form-group">
					<label for="adminId" class="col-md-2 control-label">아이디</label>
					<div class="col-md-10">
						<input type="text" class="form-control" name="adminId" value="${item.adminId}" placeholder="아이디를 입력하세요"/>
					</div>
				</div>
				
				<div class="form-group">
					<label for="passWord1" class="col-md-2 control-label">비밀번호</label>
					<div class="col-md-10">
						<input type="password" class="form-control" name="passWord1" placeholder="비밀번호를 입력하세요"/>
					</div>
				</div>
				
				<div class="form-group">
					<label for="passWord2" class="col-md-2 control-label">비밀번호 확인</label>
					<div class="col-md-10">
						<input type="password" class="form-control" name="passWord2" placeholder="비밀번호를 한번더 입력하세요"/>
					</div>
				</div>

				<div class="form-group">
					<label for="adminLevel" class="col-md-2 control-label">등급</label>
					<div class="col-md-10">
						<select name="adminLevel" class="form-control">
							<option>- 선택하세요 -</option>
							<option value="1" <c:if test="${item.adminLevel == 1}">selected</c:if>>1등급</option>
							<option value="2" <c:if test="${item.adminLevel == 2}">selected</c:if>>2등급</option>
							<option value="3" <c:if test="${item.adminLevel == 3}">selected</c:if>>3등급</option>
							<option value="4" <c:if test="${item.adminLevel == 4}">selected</c:if>>4등급</option>
							<option value="5" <c:if test="${item.adminLevel == 5}">selected</c:if>>5등급</option>
						</select>
					</div>
				</div>

				<div class="form-group">
					<div class="col-md-offset-2 col-md-10">
						<div class="row">
							<c:if test="${item.idAdmin == adminInfo.idAdmin}">
								<div class="col-md-6">
									<button type="submit" id="editAdminOk" class="btn btn-primary btn-block" formaction="editAdminOk">수정하기</button>
								</div>
								<div class="col-md-6">
									<button type="reset" class="btn btn-warning btn-block">다시작성</button>
								</div>
							</c:if>
							<c:if test="${item.idAdmin != adminInfo.idAdmin}">
								<div class="col-md-4">
									<button type="submit" id="editAdminOk" class="btn btn-primary btn-block" formaction="editAdminOk">수정하기</button>
								</div>
								<div class="col-md-4">
									<button type="reset" class="btn btn-warning btn-block">다시작성</button>
								</div>
								<div class="col-md-4">
									<button type="submit" id="deleteAdminOk" class="btn btn-danger btn-block" formaction="deleteAdminOk">삭제하기</button>
								</div>
							</c:if>
						</div>
					</div>
				</div>
			</fieldset>
		</form>
	</div>
	
	<!-- 형식검사 클래스 참조 -->
	<script src="resources/js/string.js"></script>
	<script type="text/javascript">
		$(function() {
			
			$("#deleteAdminOk").click(function() {
				if (!confirm("정말 삭제 하시겠습니까?")) {
					return false;
				}
			});
			
			$("#editAdminOk").click(function() {
				
				if (!$("input[name='nickName']").val().isValue()) {
					alert("닉네임을 입력하세요.");
					$("input[name='nickName']").focus();
					return false;
				}
				
				if (!$("input[name='adminId']").val().isValue()) {
					alert("아이디를 입력하세요.");
					$("input[name='adminId']").focus();
					return false;
				}
				
				if (!$("input[name='passWord1']").val().isValue()) {
					alert("비밀번호를 입력하세요.");
					$("input[name='passWord1']").focus();
					return false;
				}
				
				if (!$("input[name='passWord2']").val().isValue()) {
					alert("비밀번호 확인을 입력하세요.");
					$("input[name='passWord2']").focus();
					return false;
				}
				
				if ($("input[name='passWord1']").val() != $("input[name='passWord2']").val()) {
					alert("비밀번호는 동일하게 입력해야 합니다.");
					$("input[name='passWord2']").focus();
					return false;
				}
				
				if ($("select[name='adminLevel'] > option:selected").index() < 1) {
					alert("등급을 선택하세요.");
					$("select[name='adminLevel']").focus();
					return false;
				}
				
				if (!confirm("정말 수정 하시겠습니까?")) {
					return false;
				}
			});
		});
	</script>
  </body>
</html>